//获取应用实例
const app = getApp()
Page({
  data: {
    currentTab:'',
    gomony:'',
    // 组件所需的参数
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '快速充值', //导航栏 中间的标题
    },
    
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
  },
  onLoad() {
    // console.log(this.data.height)
    
  },
  
  // 选择充值金额
  selet(e){
    // console.log(e)
    var that = this;
    if (this.data.currentTab === e.currentTarget.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.currentTarget.dataset.current
      })
      if(e.currentTarget.dataset.current==0){
        that.setData({
          gomony:10
        })
      }else if(e.currentTarget.dataset.current==1){
        that.setData({
          gomony:50
        })
      }else if(e.currentTarget.dataset.current==2){
        that.setData({
          gomony:100
        })
      }else if(e.currentTarget.dataset.current==3){
        that.setData({
          gomony:200
        })
      }
    }
  },
  // 手动输入充值金额
  selpay(e){
    this.setData({
     gomony: e.detail.value
    })
  },
  // 提交，调用微信支付
  btnrecharge:function(){
    let that =this;

    let url = app.globalData.URL+'system/user/wx/pay?payMoney='+that.data.gomony;
    let data = {};
    app.wxRequest('PUT', url, data, (res) => {
      console.log(res)
      let wxzf = res.data;
      wx.requestPayment({
        timeStamp:wxzf.timeStamp,
        nonceStr: wxzf.nonceStr,
        package: wxzf.package,
        signType: wxzf.signType,
        paySign: wxzf.paySign,
        success (res) {
          console.log('支付成功')
           
        },
        fail (res) { }
      })
    }, (err) => {
      console.log(err.errMsg)
 })
    
    
    
  },
})
